"""
Case Type   : Compatibility
Case Name   : 验证临时表中的bool值输出
Create At   : 2024/10/18
Owner       : liu-tong-8848
Description :
              1.创建全局临时表
              2.临时表insert数据
              3.查询表数据
              4.清理环境
Expect      :
              1.成功
              2.成功
              3.成功
              4.清理环境成功
History     :
"""

import os
import unittest

from testcase.utils.CommonSH import CommonSH
from testcase.utils.Constant import Constant
from testcase.utils.Logger import Logger
from yat.test import Node


class SQL(unittest.TestCase):
    def setUp(self):
        self.log = Logger()
        self.Constant = Constant()
        self.primary_sh = CommonSH('PrimaryDbBmode')
        self.db_user_node = Node(node='PrimaryDbBmode')

    def test_add_dimension(self):
        self.log = Logger()
        self.log.info(f'-----{os.path.basename(__file__)} start-----')
        step1 = '--step1：创建全局临时表 expect：建表成功'
        self.log.info(step1)
        sql = "drop table if exists tab_bool_0005; create global temp table tab_bool_0005 (a bool ,c bool);"
        self.log.info(sql)
        result = self.primary_sh.execut_db_sql(sql)
        self.log.info(result)
        self.assertNotIn("ERROR", result, "执行失败" + step1)

        step2 = '--step2：临时表insert数据 expect：成功'
        self.log.info(step2)
        sql = "insert into tab_bool_0005 values (true,false),(false,true),(1,1);select c from tab_bool_0005;"
        self.log.info(sql)
        result = self.primary_sh.execut_db_sql(sql)
        self.log.info(result)
        self.assertIn(self.Constant.INSERT_SUCCESS_MSG, result, "执行失败" + step2)

        step3 = '--step3：查询表数据 expect：成功'
        self.log.info(step3)
        self.assertIn("\n f\n t\n t\n(3 rows)", result, "执行失败" + step3)

    def tearDown(self):
        step4 = 'step4:清理环境 expect:清理环境成功'
        self.log.info(step4)
        clean_sql = "drop table if exists tab_bool_0005;"
        clean_result = self.primary_sh.execut_db_sql(clean_sql)
        self.assertIn("DROP", clean_result, "执行失败" + step4)
        self.log.info(f'-----{os.path.basename(__file__)} end-----')
